$(function(){
	
	$.ajaxSetup({  
	    async : false  
	});
	$.getJSON(contextPath+'/address'
			,function(data){
		allData=data;
				for(a in data){
					var b = "<li";
					if(data[a].addressDefult == 0){
						b = b+" id='ra"+a+"'><input type='radio' name='add' id=rad"+a+" />";
					}else{
						b = b+" class='cur' id='ra"+a+"'><input type='radio' name='add' id=rad"+a+" checked='checked'/>";
						$("#uname").val(data[a].name);
						$("#phone").val(data[a].addressPhone);
						$("#address").val(data[a].addressName);
						$("#postcode").val(data[a].addressArea.areaId);
					}
					b = b+"<label for='rad"+a+"'><strong>" +data[a].name+
						"</strong><span>"+data[a].addressProvince.province
						+data[a].addressCity.city+data[a].addressArea.area
						+data[a].addressName+"</span></label>" 
						+"<div class='f_r'>" +
						"<a href='javascript:void(0);' onClick='dian("+data[a].addressId +")' class='red'>[删除]</a></div></li>";
					$("#ul-address").append(b);
				}
			});
	var a = $("#ul-address>li");
	a.each(function(){//选择地址
		$(this).click(function(){
			$("#ul-address>li").removeClass("cur");
			$(this).addClass("cur");
			$(this).find("input").attr("checked",true);
			var a = $(this).find("label").find("strong").html();
			for(b in allData){
				if(allData[b].name==a){
					$("#uname").val(allData[b].name);
					$("#phone").val(allData[b].addressPhone);
					$("#address").val(allData[b].addressName);
					$("#postcode").val(allData[b].addressArea.areaId);
				}
			}
			
		})
	})
})
$(function(){
	
})